<!--
 * @Author: your name
 * @Date: 2021-08-03 13:36:05
 * @LastEditTime: 2021-08-12 13:26:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \getHome (2)\src\components\discounts\amend.vue
-->
<!--短信通知-->
<template>
  <div>
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>通知管理</el-breadcrumb-item>
        <el-breadcrumb-item>短信通知</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center">
      <div class="hander">短信通知</div>
      <div class="entirety">
        <div class="search">
          <!-- 活动名称搜索信息 -->

          <div class="demo-input-suffix">
            通知类型

            <el-select v-model="dictCode" placeholder="请选择">
              <el-option
                v-for="item in business"
                :key="item.dictCode"
                :label="item.dictName"
                :value="item.dictCode"
              >
              </el-option>
            </el-select>
          </div>
          <!--  账号状态搜索信息 -->
          <div class="demo-input-suffix" style="margin-right:35px">
            <el-button
              style="background-color:#fd804c;color: #fff;"
              @click.native.prevent="isSelect"
              >查询</el-button
            >
            <el-button type="warning" @click.native.prevent="isEmpty"
              >清空</el-button
            >
          </div>
        </div>
      </div>

      <!--  员工列表栏位-->

      <div class="entirety">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="id" label="序号">
            <template slot-scope="scope">
              <div>
                {{ scope.row.id }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="sendNode" label="发送节点">
            <template slot-scope="scope">
              <div>
                {{ scope.row.sendNode }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="sendTemp" label="通知内容">
            <template slot-scope="scope">
              <div>
                {{ scope.row.sendTemp }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="noticeType" label="通知类型">
            <template slot-scope="scope">
              <div>
                {{ scope.row.noticeType }}
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="tempSwitch" label="通知状态">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.tempSwitch"
                :active-value="1"
                :inactive-value="0"
                @change="switchChange($event, scope.row)"
                active-color="#fb8053"
                inactive-color=""
                active-text="开启"
                inactive-text="关闭"
              >
              </el-switch>
            </template>
          </el-table-column>
          <!-- <el-table-column fixed="right" label="操作" width="170">
            <template slot-scope="scope">
       <el-button type="text" size="small" @click="isDialog('编辑通知')"
   style="color: #fc9e76;"
                  type="text"     >编辑
              </el-button>
              <el-button
                @click.native.prevent="isDel(scope.row.templateId)"
                type="text"
                   style="color: #fc9e76;"
                  type="text""
                style="color:#fd5e8e"
              >
                删除
              </el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <div class="block">
          <div class="left"></div>
          <div class="right">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              class="page"
              @size-change="sizeChangeHandle"
              @current-change="currentChangeHandle"
              :current-page="pageIndex"
              :page-size="pageSize"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        noticeType: "",
        resource: "",
        sendType: "",
        desc: ""
      },
      rules: {
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        region: [
          { required: true, message: "请选择活动区域", trigger: "change" }
        ],
        date1: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change"
          }
        ],
        date2: [
          {
            type: "date",
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ],
        type: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个活动性质",
            trigger: "change"
          }
        ],
        resource: [
          { required: true, message: "请选择活动资源", trigger: "change" }
        ],
        desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }]
      },
      iSON: true,
      pageIndex: 1,
      pageSize: 20,
      total: 0,
      msg: "",
      dialogTableVisible: false,
      dialogFormVisible: false,
      tableData: [],
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      staffName: "",
      staffPhone: "",
      searchValue: "",
      userSearch: 0,

      formLabelWidth: "120px",
      staffSearch: [
        { value: 0, label: "员工姓名" },
        { value: 1, label: "登录账号" }
      ],
      dictCode: "",
      business: [],
      multipleSelection: []
    };
  },
  activated() {
    this.DetailByPage();
    this.AllSendNode();
  },

  methods: {
    isSelect() {
      (this.pageIndex = 1), (this.pageSize = 20), this.DetailByPage();
    },

    isEmpty() {
      (this.dictCode = ""),
        (this.pageIndex = 1),
        (this.pageSize = 20),
        this.DetailByPage();
    },
    submitForm(formName) {
      //console.log("formName submit!!", formName);

      this.$refs[formName].validate(valid => {
        //console.log("valid submit!!", valid);

        if (valid) {
          this.dialogFormVisible = false;
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },
    isDialog(type) {
      this.msg = type;

      this.dialogFormVisible = true;

      //console.log("num,,,,,弹框内容,,", type);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    handleSelectionChange(val) {
      //console.log("handleSelectionChange,,,,,,,", val);
      this.multipleSelection = val;
    },

    //导出
    isExport(tableData) {
      //console.log(tableData);
    },

    //分页获取优惠券模板列表接口调用
    DetailByPage() {
      this.$http({
        url: `/messageadmin/sms/selectSmsNotify`,
        method: "GET",
        params: {
          dictCode: this.dictCode,
          pageNum: this.pageIndex,
          pageSize: this.pageSize
        }
      }).then(res => {
        this.tableData = res.data.list;

        this.total = parseInt(res.data.total);
      });
    },

    switchChange(e, data) {
      //console.log(e, "aing");
      //console.log(data, "data");

      let message = "";
      if (e == 1) {
        message = "开启成功 !";
        this.$http({
          url: `/messageadmin/sms/updateSmsTempSwitch`,
          method: "POST",
          data: {
            templateId: data.templateId,
            tempSwitch: 1
          }
        }).then(res => {
          if (res.success == 1) {
            return this.$message({ type: "success", message });
          } else {
            return this.$message.error("开启失败");
          }
        });
      } else if (e == 0) {
        message = "停用成功 !";
        this.$http({
          url: `/messageadmin/sms/updateSmsTempSwitch`,
          method: "POST",
          data: {
            templateId: data.templateId,
            tempSwitch: 0
          }
        }).then(res => {
          if (res.success == 1) {
            return this.$message({ type: "success", message });
          } else {
            return this.$message.error("停用失败");
          }
        });
      }
    },

    //删除短信通知模板
    isDel(data) {
      let message = "删除成功 !";
      this.$http({
        url: `/messageadmin/sms/deleteSmsTemp`,
        method: "POST",
        data: {
          templateId: data
        }
      }).then(res => {
        if (res.success == 1) {
          this.DetailByPage();

          this.$message({ type: "success", message });
          return;
        } else {
          return this.$message.error("删除失败");
        }
      });
    },

    //查询所有通知类型
    AllSendNode() {
      this.$http({
        url: `/messageadmin/sms/selectSmsNoticeType`,
        method: "GET"
      }).then(res => {
        this.business = res.data;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
.news {
  margin-left: 60%;
}
.entirety {
  width: 95%;
  margin: 10px;
  border: 7px solid #fafafa;
  border-radius: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;

    margin-left: 1%;
  }
}

.overall {
  width: 100%;
  height: auto;
  display: flex;

  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 2%;
}
.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}

/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
</style>
